<div class="task">
<?php include ('buttons.tpl'); ?>
</div>

<?php if ($error) { ?>
<div class="warning"><?php echo $error; ?></div>
<?php } ?>

<h2><?php echo $heading_title; ?></h2>
<div class="description"><?php echo $heading_description; ?></div>

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
  <div id="tabs">
	<ul>
	  <li><a href="#tabs-1"><?php echo $tab_general; ?></a></li>
	  <li><a href="#tabs-2"><?php echo $tab_data; ?></a></li>
	  <li><a href="#tabs-3"><?php echo $tab_image; ?></a></li>
	  <li><a href="#tabs-4"><?php echo $tab_discount; ?></a></li>
	  <?php if ($downloads) {?><li><a href="#tabs-5"><?php echo $tab_download; ?></a></li><?php } ?>
	  <li><a href="#tabs-6"><?php echo $tab_category; ?></a></li>
	  <li><a href="#tabs-7"><?php echo $tab_meta; ?></a></li>
	</ul>
	<div id="tabs-1">
	  <?php foreach ($products as $product) { ?>
      <fieldset>
        <legend><?php echo $product['language']; ?></legend>
        <table>
          <tr>
            <td width="185"><span class="required">*</span> <?php echo $entry_name; ?></td>
            <td><input name="name[<?php echo $product['language_id']; ?>]" value="<?php echo $product['name']; ?>" size="100" />
            <?php if ($error_name) { ?>
            <span class="error"><?php echo $error_name; ?></span>
            <?php } ?></td>
          </tr>
          <tr>
            <td valign="top"><?php echo $entry_description; ?></td>
            <td><textarea name="description[<?php echo $product['language_id']; ?>]" id="description<?php echo $product['language_id']; ?>" class="editor"><?php echo $product['description']; ?></textarea>
          </tr>
        </table>
      </fieldset>
      <?php } ?>
	</div>
	
	<div id="tabs-2">
	  <table>
         <tr>
          <td><?php echo $entry_status; ?></td>
          <td><select name="status">
              <?php if ($status == '1') { ?>
              <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
              <option value="0"><?php echo $text_disabled; ?></option>
              <?php } else { ?>
              <option value="1"><?php echo $text_enabled; ?></option>
              <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
              <?php } ?>
            </select></td>
        </tr>
        <tr>
          <td width="185"><?php echo $entry_model; ?></td>
          <td><input name="model" value="<?php echo $model; ?>" />
        </tr>
        <tr>
          <td><?php echo $entry_price; ?></td>
          <td><input name="price" value="<?php echo $price; ?>" /></td>
        </tr>
        <tr>
          <td><?php echo $entry_weight; ?></td>
          <td><input name="weight" value="<?php echo $weight; ?>" /></td>
        </tr>
        <tr>
          <td><?php echo $entry_weight_class; ?></td>
          <td><select name="weight_class_id">
              <?php foreach ($weight_classes as $weight_class) { ?>
              <?php if ($weight_class['weight_class_id'] == $weight_class_id) { ?>
              <option value="<?php echo $weight_class['weight_class_id']; ?>" selected="selected"><?php echo $weight_class['title']; ?></option>
              <?php } else { ?>
              <option value="<?php echo $weight_class['weight_class_id']; ?>"><?php echo $weight_class['title']; ?></option>
              <?php } ?>
              <?php } ?>
            </select></td>
        </tr>
        <tr>
          <td><?php echo $entry_quantity; ?></td>
          <td><input name="quantity" value="<?php echo $quantity; ?>" size="2" /></td>
        </tr>
        <tr>
          <td><?php echo $entry_min_qty; ?></td>
          <td><input name="min_qty" value="<?php echo $min_qty; ?>" size="2" /></td>
        </tr>
        <tr>
          <td><?php echo $entry_shipping; ?></td>
          <td><?php if ($shipping == 1) { ?>
            <input type="radio" name="shipping" value="1" checked="checked" />
            <?php echo $text_yes; ?>
            <input type="radio" name="shipping" value="0" />
            <?php echo $text_no; ?>
            <?php } else { ?>
            <input type="radio" name="shipping" value="1" />
            <?php echo $text_yes; ?>
            <input type="radio" name="shipping" value="0" checked="checked" />
            <?php echo $text_no; ?>
            <?php } ?></td>
        </tr>
        <tr>
          <td><?php echo $entry_tax_class; ?></td>
          <td><select name="tax_class_id">
              <option value="0"><?php echo $text_none; ?></option>
              <?php foreach ($tax_classes as $tax_class) { ?>
              <?php if ($tax_class['tax_class_id'] == $tax_class_id) { ?>
              <option value="<?php echo $tax_class['tax_class_id']; ?>" selected="selected"><?php echo $tax_class['title']; ?></option>
              <?php } else { ?>
              <option value="<?php echo $tax_class['tax_class_id']; ?>"><?php echo $tax_class['title']; ?></option>
              <?php } ?>
              <?php } ?>
            </select></td>
        </tr>
        <tr>
          <td><?php echo $entry_manufacturer; ?></td>
          <td><select name="manufacturer_id">
              <option value="0" selected="selected"><?php echo $text_none; ?></option>
              <?php foreach ($manufacturers as $manufacturer) { ?>
              <?php if ($manufacturer['manufacturer_id'] == $manufacturer_id) { ?>
              <option value="<?php echo $manufacturer['manufacturer_id']; ?>" selected="selected"><?php echo $manufacturer['name']; ?></option>
              <?php } else { ?>
              <option value="<?php echo $manufacturer['manufacturer_id']; ?>"><?php echo $manufacturer['name']; ?></option>
              <?php } ?>
              <?php } ?>
            </select></td>
        </tr>
        <tr>
          <td><?php echo $entry_date_available; ?></td>
          <td><input name="date_available_day" value="<?php echo $date_available_day; ?>" size="2" maxlength="2" />
            <select name="date_available_month">
              <?php foreach ($months as $month) { ?>
              <?php if ($month['value'] == $date_available_month) { ?>
              <option value="<?php echo $month['value']; ?>" selected="selected"><?php echo $month['text']; ?></option>
              <?php } else { ?>
              <option value="<?php echo $month['value']; ?>"><?php echo $month['text']; ?></option>
              <?php } ?>
              <?php } ?>
            </select>
            <input name="date_available_year" value="<?php echo $date_available_year; ?>" size="4" maxlength="4" />
            <?php if ($error_date_available) { ?>
            <span class="error"><?php echo $error_date_available; ?></span>
            <?php } ?></td>
        </tr>
        <tr>
          <td><?php echo $entry_sort_order; ?></td>
          <td><input name="sort_order" value="<?php echo $sort_order; ?>" size="1" /></td>
        </tr>
        
        <tr>
          <td valign="top"><?php echo $entry_related; ?></td>
          <td>
          <div style="height:200px; overflow:auto;" class="overflow">
          <table width="100%">
	        <?php $j = 1; ?>
	        <?php $i = 1; ?>
	        <?php foreach ($related as $r) { ?>
	        <?php if($j != 1) {$j = 1;}else{$j = 0;} ?>
			<?php if($j == 0) {$class = 'row1';}elseif($j == 1){$class = 'row2';}	?>
    		<tr class="<?php echo $class; ?>" onmouseover="this.className='highlight'" onmouseout="this.className='<?php echo $class; ?>'">
              <td><input name="related[<?php echo $i; ?>][id]" type="checkbox" value="<?php echo $r['related_id']; ?>" <?php echo ($r['product_id'])?'checked="checked"':''?>/></td>
              <td><?php echo $r['related_id']; ?></td>
              <td><?php echo $r['title']; ?></td>
              <td><input name="related[<?php echo $i; ?>][cross]" type="checkbox" title="<?php echo $text_related_cross; ?>" value="1" /></td>
            </tr>
            <?php $i++; ?>
            <?php } ?>
          </table>
          </div>
          </td>              
        </tr>
      </table>
	</div>
	
	<div id="tabs-3">
	  <table>
        <tr>
          <td width="185"><?php echo $entry_upload; ?></td>
          <td><input type="file" name="image" />
            <?php if ($error_upload) { ?>
            <span class="error"><?php echo $error_upload; ?></span>
            <?php } ?></td>
        </tr>
        <tr>
          <td></td>
          <td><?php echo $text_or; ?></td>
        </tr>
        <tr>
          <td></td>
		  <td><span class="image" id="image_preview"></span></td>
		</tr>
		<tr>
		  <td><?php echo $entry_image; ?></td>
		  <td><select name="image_id" id="image_id">
		  <?php foreach ($images as $image) {?>
		  <option value="<?php echo $image['image_id']; ?>" <?php if ($image['image_id'] == $image_id) { ?> selected<?php } ?>><?php echo $image['title']; ?></option>
		  <?php } ?>
		  </select>
		  <input type="button" name="image_preview_less" id="image_preview_less" value="&laquo;" />
		  <input type="button" name="image_preview_more" id="image_preview_more" value="&raquo;" />
		  </td>
        </tr>
        <tr>
          <td></td>
	      <td></td>
        </tr>
        <tr>
          <td valign="top"><?php echo $entry_images; ?></td>
          <td>
          <div style="height:200px; overflow:auto;" class="overflow">
          <table width="100%">
	        <?php $j = 1; ?>
	        <?php foreach ($images as $image) { ?>
	        <?php if($j != 1) {$j = 1;}else{$j = 0;} ?>
			<?php if($j == 0) {$class = 'row1';}elseif($j == 1){$class = 'row2';}	?>
    		<tr class="<?php echo $class; ?>" onmouseover="this.className='highlight'" onmouseout="this.className='<?php echo $class; ?>'">
              <?php if (!$image['product_id']) { ?>
              <td><input name="image[]" type="checkbox" value="<?php echo $image['image_id']; ?>" /></td>
              <td><?php echo $image['image_id']; ?></td>
              <td><?php echo $image['title']; ?></td>
              <?php } else { ?>
              <td><input name="image[]" type="checkbox" value="<?php echo $image['image_id']; ?>" checked="checked" /></td>
              <td><?php echo $image['image_id']; ?></td>
              <td><?php echo $image['title']; ?></td>
              <?php } ?>
            </tr>
            <?php } ?>
          </table>
          </div>
          </td>
        </tr>
      </table>
	</div>
	
	<div id="tabs-4">
	  <table id="discounts">
        <?php $i = 0; ?>
        <?php foreach ($product_discounts as $product_discount) { ?>
        <tr id="discount_<?php echo $i; ?>">
          <td><?php echo $entry_quantity; ?></td>
          <td><input type="text" name="product_discount[<?php echo $i; ?>][quantity]" value="<?php echo $product_discount['quantity']; ?>" size="2" /></td>
          <td><?php echo $entry_discount; ?></td>
          <td><input type="text" name="product_discount[<?php echo $i; ?>][discount]" value="<?php echo $product_discount['discount']; ?>" /></td>
          <td><input type="button" value="<?php echo $button_remove; ?>" onclick="removeDiscount('discount_<?php echo $i; ?>');" /></td>
        </tr>
        <?php $i++; ?>
        <?php } ?>
      </table>
      <table>
        <tr>
          <td colspan="5"><input type="button" value="<?php echo $button_add; ?>" onclick="addDiscount();" /></td>
        </tr>
      </table>
	</div>
	
	<?php if ($downloads) {?>
	<div id="tabs-5">
	  <table>
        <tr>
          <td width="185" valign="top"><?php echo $entry_download; ?></td>
          <td><select name="download[]" multiple="multiple">
              <?php foreach ($downloads as $download) { ?>
              <?php if (!$download['product_id']) { ?>
              <option value="<?php echo $download['download_id']; ?>"><?php echo $download['name']; ?></option>
              <?php } else { ?>
              <option value="<?php echo $download['download_id']; ?>" selected="selected"><?php echo $download['name']; ?></option>
              <?php } ?>
              <?php } ?>
            </select></td>
        </tr>
      </table>
	</div>
	<?php } ?>
	
	<div id="tabs-6">
	  <table>
        <tr>
          <td width="185" valign="top"><?php echo $entry_category; ?></td>
          <td><select name="category[]" multiple="multiple">
              <?php foreach ($categories as $category) { ?>
              <?php if (!$category['product_id']) { ?>
              <option value="<?php echo $category['category_id']; ?>"><?php echo $category['name']; ?></option>
              <?php } else { ?>
              <option value="<?php echo $category['category_id']; ?>" selected="selected"><?php echo $category['name']; ?></option>
              <?php } ?>
              <?php } ?>
            </select></td>
        </tr>
      </table>
	</div>
	
	<div id="tabs-7">
	  <?php foreach ($products_meta as $product_meta) { ?>
      <fieldset>
        <legend><?php echo $product_meta['language']; ?></legend>
        <table>
          <tr>
            <td valign="top" width="185"><?php echo $entry_meta_keys; ?></td>
            <td><textarea name="meta_keys[<?php echo $product_meta['language_id']; ?>]" cols="100" rows="2"><?php echo $product_meta['meta_keys']; ?></textarea>
          </tr>
          <tr>
            <td valign="top"><?php echo $entry_meta_description; ?></td>
            <td><textarea name="meta_description[<?php echo $product_meta['language_id']; ?>]" cols="100" rows="5"><?php echo $product_meta['meta_description']; ?></textarea>
          </tr>
        </table>
      </fieldset>
      <?php } ?>
	</div>
  </div>
  <script type="text/javascript"><!--
	$(function() {
		$("#tabs").tabs();
	});
  //--></script>
</form>

<script type="text/javascript"><!--
	function addDiscount() {
		$.ajax({
			type:    'GET',
			url:     'index.php?controller=product&action=discount&discount_id='+$('#discounts tr').size(),
			async:   false,
			success: function(data) {
			$('#discounts').append(data);
			}
		});
	}
	  
	function removeDiscount(row) {
  		$('#'+row).remove();
	}
//--></script>

<script type="text/javascript"><!--
	$('#image_preview').load('index.php?controller=image&action=view&image_id='+$('#image_id').val());
	$("#image_preview_more").click(function(){
	var val = parseInt($('#image_id').val())+1;
	$('#image_id').val(val);
	$('#image_preview').load('index.php?controller=image&action=view&image_id='+$('#image_id').val());
	});
	$("#image_preview_less").click(function(){
	var val = parseInt($('#image_id').val())-1;
	$('#image_id').val(val);
	$('#image_preview').load('index.php?controller=image&action=view&image_id='+$('#image_id').val());
	});
	$("#image_id").click(function(){
	$('#image_preview').load('index.php?controller=image&action=view&image_id='+$(this).val());
	});
	//$("#image_id option").hover(function(){
	//$('#image_preview').load('index.php?controller=image&action=view&image_id='+$(this).val());
	//});
//--></script>
<?php if (isset($editor)) { echo $editor; } ?>